package com.designpatterns.iterator.concreteaggregate;

import com.designpatterns.iterator.aggregate.List;
import com.designpatterns.iterator.concreteiterator.IteratorImpl;
import com.designpatterns.iterator.iterator.Iterator;

/**
 * ListImpl Class Implements List Interface
 * @see List
 *
 * @author Haiqi.Wang
 * @since 2013-6-9下午4:28:49
 */
public class ListImpl implements List {

	private Object[] list;
	private int index;
	private int size;
	
	public ListImpl() {
		index = 0;
		size = 0;
		list = new Object[100];
	}
	
	@Override
	public Iterator iterator() {
		return new IteratorImpl(this);
	}

	@Override
	public Object get(int index) {
		return list[index];
	}

	@Override
	public int getSize() {
		return this.size;
	}

	@Override
	public void add(Object obj) {
		list[index++] = obj;
		size ++;
	}

}
